package io;

import java.io.Serializable;
import java.util.Arrays;

/**
 * 使用Person类测试对象流的序列化和反序列化操作
 */

/*对象输出流在进行序列化时，要求该对象必须实现可序列化接口Serializable
 * 否则调用writeObject()时会发生NotSerializableException异常*/
public class Person implements Serializable {
    private String name;
    private int age;
    private String gender;
    //被transient修饰的属性在序列化会被忽略，可以达到对象瘦身的效果
    private transient String[] otherInfo;

    public Person() {
    }

    public Person(final String name, final int age, final String gender, final String[] otherInfo) {
        this.name = name;
        this.age = age;
        this.gender = gender;
        this.otherInfo = otherInfo;
    }

    public String getName() {
        return this.name;
    }

    public void setName(final String name) {
        this.name = name;
    }

    public int getAge() {
        return this.age;
    }

    public void setAge(final int age) {
        this.age = age;
    }

    public String getGender() {
        return this.gender;
    }

    public void setGender(final String gender) {
        this.gender = gender;
    }

    public String[] getOtherInfo() {
        return this.otherInfo;
    }

    public void setOtherInfo(final String[] otherInfo) {
        this.otherInfo = otherInfo;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", gender='" + gender + '\'' +
                ", otherInfo=" + Arrays.toString(otherInfo) +
                '}';
    }
}
